package org.qy.star_server.core;

import lombok.Data;

import java.util.Objects;

/**
 * @author yinger
 * @description 绑定交换机和队列 辅助交换机完成转发
 * @date 2024/3/26 07:41
 **/
@Data
public class Binding {
    private String queueName;
    private String bindingKey;
    private String exchangeName;
    private String virtualHostName;
    private String username;
    private int deleted = 0;

    public Binding(String username, String virtualHostName, String exchangeName, String queueName, String bindingKey) {
        this.queueName = queueName;
        this.bindingKey = bindingKey;
        this.exchangeName = exchangeName;
        this.virtualHostName = virtualHostName;
        this.username = username;
    }

    public static Binding getInsertBinding(String username, String virtualHostName, String exchangeName, String queueName, String bindingKey) {
        return new Binding(username, virtualHostName, exchangeName, queueName, bindingKey);
    }

    public static Binding getQueryBinding(String username, String virtualHostName, String exchangeName, String queueName) {
        return new Binding(username, virtualHostName, exchangeName, queueName, null);
    }

    public Binding() {
    }


    @Data
    public static class BindingeGloballyUniqueIdentity {
        private final String username;
        private final String virtualHostName;
        private final String exchangeName;
        private final String queueName;

        public BindingeGloballyUniqueIdentity(String username, String virtualHostName, String exchangeName, String queueName) {
            this.username = username;
            this.virtualHostName = virtualHostName;
            this.exchangeName = exchangeName;
            this.queueName = queueName;
        }

        @Override
        public boolean equals(Object object) {
            if (this == object) return true;
            if (object == null || getClass() != object.getClass()) return false;
            BindingeGloballyUniqueIdentity that = (BindingeGloballyUniqueIdentity) object;
            return Objects.equals(username, that.username) && Objects.equals(virtualHostName, that.virtualHostName) && Objects.equals(exchangeName, that.exchangeName) && Objects.equals(queueName, that.queueName);
        }

        @Override
        public int hashCode() {
            return Objects.hash(username, virtualHostName, exchangeName, queueName);
        }
    }

}
